#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include<sys/wait.h>
#include<sys/types.h>
using namespace std;
pid_t pid=0;
void handle(int signo)
{
    waitpid(pid,NULL,0);
    
}
int main()
{
  signal(SIGCHLD,handle);
  pid=fork();
  if(pid==0)
  {
    cout<<"子进程pid:"<<pid<<endl;
    while(1)
    {

    }
  }
  else
  {
    cout<<"父进程pid:"<<pid<<endl;
  while(1)
  {

  }

  }
}

/*void handle(int signo)
{
  printf("我是信号%d\n", signo);
  int cnt = 32;
  sigset_t set;
  while (cnt--)
  {
    sigpending(&set);
    for (int i = 1; i <= 31; i++)
    {
      if (sigismember(&set, i))
      {
        printf("1");
      }
      else
      {
        printf("0");
      }

      

      
    }
    printf("\n");
    sleep(1);
  }
}
int main()
{
  printf("我的pid是%d\n",getpid());
  sigset_t set;
  sigemptyset(&set);
  sigaddset(&set, 3);
  sigaddset(&set, 4);
  sigaddset(&set, 5);
  struct sigaction act;
  struct sigaction oact;
  memset(&act, 0, sizeof(act));
  act.sa_flags = 0;
  act.sa_mask = set;
  act.sa_handler = handle;
 memset(&oact, 0, sizeof(oact));
  sigaction(2, &act, &oact);
  while (1)
  {
  }

  return 0;
}*/
